<#include "../common/layoutWithOutDocType.ftl"/>
<@layoutWithOutDocType>


<table width="100%">
<tr>

<td width="60%" valign="top">
  <div class="well" style="height:800px">
  		<!--百度地图容器-->
  	<div id="container"></div>
  	<div id="results"></div>
<style type="text/css"> 
#container{height:100%}

  td {   font-size: 9pt;color=#3333FF;height:23pt;nowrap}

</style> 
<!--引用百度地图API-->
<script type="text/javascript" src="/js/showBo.js"></script>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=VVxB3u2hT9wlF2QfiHqu7zNx"></script>
<script type="text/javascript" src="/js/MarkerTool.js"></script>
<script type="text/javascript" src="http://api.map.baidu.com/library/TextIconOverlay/1.2/src/TextIconOverlay_min.js"></script>
<script type="text/javascript" src="http://api.map.baidu.com/library/DistanceTool/1.2/src/DistanceTool_min.js"></script>
<script type="text/javascript" src="/js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="/js/bootstrap-datetimepicker.zh-CN.js"></script>
<script type="text/javascript" src="/js/checkArea.js"></script>
<script type="text/javascript" src="/js/jquery.spinner.js"></script>
<script type="text/javascript" src="/js/order_type.js"></script>
	
<script>
 var beginPoint ;
 var endPoint ;
 var map;
 var issubmit=false;
 var cityPostion = "${session.syscity!""}";
	 
	//创建和初始化地图函数：
    function initMap(){
        createMap();//创建地图
        setMapEvent();//设置地图事件
        addMapControl();//向地图添加控件
    }
    
    //创建地图函数：
    function createMap(){
        map = new BMap.Map("container");//在百度地图容器中创建一个地图
        //var point = new BMap.Point(121.488186,31.225696);//定义一个中心点坐标<上海>
        //map.centerAndZoom(point,12);//设定地图的中心点和坐标并将地图显示在地图容器中
        
        <#if session.syscity??>
            <#if session.syscity?length gt 0>
        		map.centerAndZoom("${session.syscity}", 12);
        	<#else>
            	map.centerAndZoom("上海", 12);
        	</#if>
        <#else>
            map.centerAndZoom("上海", 12);
        </#if>
        window.map = map;//将map变量存储在全局
    }
    //地图事件设置函数：
    function setMapEvent(){
        map.enableDragging();//启用地图拖拽事件，默认启用(可不写)
        map.enableScrollWheelZoom();//启用地图滚轮放大缩小
        map.enableDoubleClickZoom();//启用鼠标双击放大，默认启用(可不写)
        map.enableKeyboard();//启用键盘上下左右键移动地图
    }
    
    //地图控件添加函数：
    function addMapControl(){
	    //向地图中添加缩放控件
		var ctrl_nav = new BMap.NavigationControl({anchor:BMAP_ANCHOR_TOP_LEFT,type:BMAP_NAVIGATION_CONTROL_LARGE});
		map.addControl(ctrl_nav);
	    //向地图中添加缩略图控件
		var ctrl_ove = new BMap.OverviewMapControl({anchor:BMAP_ANCHOR_BOTTOM_RIGHT,isOpen:1});
		map.addControl(ctrl_ove);
	    //向地图中添加比例尺控件
		var ctrl_sca = new BMap.ScaleControl({anchor:BMAP_ANCHOR_BOTTOM_LEFT});
		map.addControl(ctrl_sca);
    }
    
    
    
    initMap();
	

    
    /*$(document).ready(function(){
		
		$("#serverDate").datetimepicker({ format: 'yyyy-mm-dd', language: 'zh-CN', minView: 'month', pickDate: true, pickTime: false, inputMask: false, autoclose: true });
		
		$("#serverTime").datetimepicker({ format: 'HH:ii', language: 'zh-CN',minView: 'hour', startView: 'day', pickDate: true, pickTime: true, inputMask: false, autoclose: true,startDate:'${varDate!""}' });
		
		$("#paidanTime").datetimepicker({ format: 'yyyy-mm-dd HH:ii', language: 'zh-CN', pickDate: true, pickTime: true, inputMask: false, autoclose: true });
    
    });*/
    
    
    function markBegin(){
	    var mkrTool = new BMapLib.MarkerTool(map,{followText: "点击地图添加标注"});
	    mkrTool.addEventListener("markend", function(evt){ 
		    beginPoint = evt.marker;
		    beginPoint.enableDragging(true); // 设置标注可拖拽
		    $("#startpoint_longitude").val(beginPoint.getPosition().lng);
			 $("#startpoint_latitude").val(beginPoint.getPosition().lat);
			 
		    beginPoint.addEventListener("dragend" , function(){
			     $("#startpoint_longitude").val(beginPoint.getPosition().lng);
			 	 $("#startpoint_latitude").val(beginPoint.getPosition().lat);
		    	  
			     var pt = beginPoint.getPosition();
			      
			     var gc = new BMap.Geocoder();
			     gc.getLocation(pt, function(rs){
				    var addComp = rs.addressComponents;
				    //$("#startpoint").val(addComp.district + addComp.street + addComp.streetNumber);
				    route();
				});  
		    })
		    //TODO
		    var gc = new BMap.Geocoder(); 
		    var pt = beginPoint.point; 

		   markerComplete(pt.lng,pt.lat);
		   
		     gc.getLocation(pt, function(rs){
			    var addComp = rs.addressComponents;
			    var  s=$("#startpoint").val();
			    //if(s.length==0)
			    	//$("#startpoint").val(addComp.district + addComp.street + addComp.streetNumber);
			});  
		   //获取司机
			 $.ajax({
					url:'/order/ajaxAssignment',
					data:{"order.startpoint_longitude":$("#startpoint_longitude").val(),
								"order.startpoint_latitude":$("#startpoint_latitude").val()},
					success:function(data){
						dirverList=data.driverList;
						driverShow=data.driverShowList;
						initAllMarker(dirverList);
						markerUser($("#startpoint_longitude").val(),$("#startpoint_latitude").val());
						addDriver(driverShow);
						$("#driverTable").css('display','block');
						$("#showTable").css('display','');
						$('#selectTd').css('display','');
					}
				});
		});
	
	     mkrTool.open(); //打开工具 
	     var icon= new BMap.Icon('/img/marker/start.png', new BMap.Size(38, 33), {
    			imageOffset: new BMap.Size(0, 0)    //图片的偏移量。为了是图片底部中心对准坐标点。
	  			}
			);
		 mkrTool.setIcon(icon);
		 $("#beginChooser").attr("disabled" , true);
		 
		 
	 }
	 
	 function checkMobile(mobile)
	 {

	 			$.ajax({
				    type : "POST",
				    url : "/member/findByPhone",
				    dataType : "json",
				     data: {'phone':mobile},
				    success : function(data) {
				    if(data.member)
				    {
				    	if(data.member.status == 2){
				    		alert('这个客户是黑名单，请谨慎操作');
				    	}
				    	
				    	$("#clientPhone").val(data.member.cell_phone);
				    	$("#clientName").val(data.member.real_name);
				    	$("#memberID").val(data.member.id);
				    	$("#clientVirtual").text(data.finishmoney+"元");
				    	
				    	if(data.member.sex==0)
				    	$("#membertype").html("男");
				    	if(data.member.sex==1)
				    	$("#membertype").html("女");
				    	if(data.member.sex==2)
				    	$("#membertype").html("未知");
				    	
				    	//$("#allcount").html(data.order_count);
				    	$("#allcount").html("<a target='_blank' href='/order/memberOrder/"+data.member.id+"'>"+data.order_count+"</a>");
				    	
				    	$("#cancalcount").html(data.cancel_order_count);
    					$("#monthcount").html(data.month_order_count);
    					$("#todayordernums_div").slideDown();
				    	
				    	
				    	
				    }
				    else
				    {
				    	$("#clientName").val("");
				    	$("#memberID").val("");
				    	$("#clientVirtual").text("0元");
				    	
				    	$("#membertype").html("未知");
						            
				    	$("#allcount").html("0");

				    	$("#cancalcount").html("0");
    					$("#monthcount").html("0");
    					$("#todayordernums_div").slideUp();
				    }
				    
				        
				       // console.info(data);
				    },
				    error : function(textStatus) {
				        //alert("出错");
				    }
				});
				
				
	 	/*
	 			$.get('/member/findByPhone',{'phone':mobile},function(data){
    			if(data.success){
    				$("#clientName").val(data.object.name);
    				$("#clientVirtual").text(data.object.member.virtual+"元");
    				
    				$("#allcount").html(data.countnum);
    				$("#monthcount").html(data.longValue);
    				$("#membertype").html(data.object.member.type);
    				$("#todayordernums_div").slideDown();
    				
    				if(data.data && data.data.length>0){
    					$(".memberOrders-tr").remove();
    					$(data.data).each(function(index,element){
	    					var content="<tr class='memberOrders-tr'>";
    						if(element.status==0){
    							content+="<td><span class='label label-info'>新订单</span></td>";
							}
    						else if(element.status==1){
    							content+="<td><span class='label label-warning'>已派单</span></td>";
							}
							else{
								content+="<td><span class='label label-danger'>服务中</span></td>";
							}
    						content+="<td><a target='_blank' href='/order/detail/"+element.id+"'>***"+element.orderNumber.substring(8)+"</a></td>"+
									"<td>"+element.orderType+"</td>"+
									"<td>"+element.fromSource+"</td>"+
									"<td>"+element.serverTimeHI+"</td>"+
									"<td>"+element.fromPlace+"</td>"+
									"<tr>";
    						$("#memberOrders-table tbody").append(content);
    					});
    					
    					$("#memberOrders-table").show();
    				}
    				else{
    					$("#memberOrders-table").hide();
    				}
    				
    			}
    			else{
    				$("#todayordernums_div p").html('');
    				$("#todayordernums_div").slideUp();
    				$("#memberOrders-table").hide();
    				$("#clientVirtual").text("0元");
    				$("#membertype").html("");
    			}
    		});
    		
    	*/	
	 }
	 
	//改变驾车路线回调
	function markerComplete(lng,lat){
		//附近司机
	    $.get('/driver/listdistance',{'longitude':lng,'latitude':lat},function(data,status){

	    	$(".drivers-tr").remove();
	    	if(status=="success"){
				if(data && data.length>0){
					$(data).each(function(i,driver){
						var content="<tr class='drivers-tr'>"+
									"<td><input type='checkbox' name='check_drivers' value='"+driver.id+"' /></td>"+
									"<td>"+driver.realname+"</td>"+
									"<td>"+driver.distance+"</td>"+
									"<td>"+driver.todayOrders+"次</td>"+
									"<td>"+driver.monthOrders+"次</td>"+
									"<tr>";
						$("#drivers-table tbody").append(content);
					});
				}
			}
			else
			{
				alert("查找附近司机失败");
			}
		});
	}	 
	
	 function markEnd(){
	    var mkrTool = new BMapLib.MarkerTool(map,{followText: "点击地图添加标注"});
	    mkrTool.addEventListener("markend", function(evt){ 
		    endPoint = evt.marker;
		    endPoint.enableDragging(true); // 设置标注可拖拽
		    $("#endpoint_longitude").val(endPoint.getPosition().lng);
			$("#endpoint_latitude").val(endPoint.getPosition().lat);
		    endPoint.addEventListener("dragend" , function(){
			     $("#endpoint_longitude").val(endPoint.getPosition().lng);
				 $("#endpoint_latitude").val(endPoint.getPosition().lat);
		    	 var gc = new BMap.Geocoder(); 
			     var pt = endPoint.point; 
			     gc.getLocation(pt, function(rs){
				    var addComp = rs.addressComponents;
				    //$("#endpoint").val(addComp.district + addComp.street + addComp.streetNumber);
				    route();
				});  
		    })
		    //alert(marker.getPosition().lng + " , " + marker.getPosition().lat);
		    var gc = new BMap.Geocoder(); 
		     var pt = endPoint.point; 
		     gc.getLocation(pt, function(rs){
			    var addComp = rs.addressComponents;
			    //$("#endpoint").val(addComp.district + addComp.street + addComp.streetNumber);
			    route();
			});  
		});
	     mkrTool.open(); //打开工具 
	     var icon= new BMap.Icon('/img/marker/end.png', new BMap.Size(38, 33), {
    			imageOffset: new BMap.Size(0, 0)    //图片的偏移量。为了是图片底部中心对准坐标点。
	  			}
			);
		 mkrTool.setIcon(icon);
		 $("#endChooser").attr("disabled" , true);
	 }
	 
	 function route(){
	 	var output = "";
		var searchComplete = function (results){
		    if (transit.getStatus() != BMAP_STATUS_SUCCESS){
		        return ;
		    }
		   var plan = results.getPlan(0);
		   $("#kilometre_adv").text(plan.getDistance(true));
		}
		var transit = new BMap.DrivingRoute(map, {renderOptions: {map: map},
		    onSearchComplete: searchComplete,
		    onPolylinesSet: function(){        
		        setTimeout(function(){},"1000");
		    }});
		if(beginPoint && endPoint){
			transit.search(beginPoint.getPosition(), endPoint.getPosition());
		}
	 }
	 
	 function search(){
	 	var local = new BMap.LocalSearch(map, {
		  renderOptions: {map: map, panel: "results"}
		});
		
		local.search($("#startpoint").val());
	 }
	 
	 function searchEnd(){
	 	var local = new BMap.LocalSearch(map, {
		  renderOptions: {map: map, panel: "results"}
		});
		
		local.search($("#endpoint").val());
	 }
	 function dis(){
	 	  var myDis = new BMapLib.DistanceTool(map);
	 	  myDis.open();
	 }
	 
	function reduce1()
	{
		var num=$("#driverNum").val();
		num=num-1;
		if(num<1) num=1;
		$("#driverNum").val(num);
	}
	function add1()
	{
		var num=parseInt($("#driverNum").val());
		num=num+1;
		$("#driverNum").val(num);
	}	 
	
	function reduce2()
	{
		var num=$("#driverKm").val();
		num=num-1;
		if(num<1) num=1;
		$("#driverKm").val(num);
	}
	function add2()
	{
		var num=parseInt($("#driverKm").val());
		num=num+1;
		$("#driverKm").val(num);
	}
	
	function reduce3()
	{
		var num=$("#driverMoney").val();
		num=num-1;
		if(num<0) num=0;
		$("#driverMoney").val(num);
	}
	function add3()
	{
		var num=parseInt($("#driverMoney").val());
		num=num+1;
		$("#driverMoney").val(num);
	}
	
	function reduce4()
	{
		var num=$("#driverRateKm").val();
		num=num-1;
		if(num<1) num=1;
		$("#driverRateKm").val(num);
	}
	function add4()
	{
		var num=parseInt($("#driverRateKm").val());
		num=num+1;
		$("#driverRateKm").val(num);
	}
	 
	 function formCheck(){
	 		if($("#startpoint_longitude").val().length==0 || $("#startpoint_latitude").val().length==0){
				//$.scojs_message("请先在地图上指定 定位代驾地点", $.scojs_message.TYPE_ERROR);
				alert("请选择出发地址");
				return false;
			}
			/*if($("#endpoint_latitude").val().length==0 || $("#endpoint_longitude").val().length==0){
				alert("请选择收货地址");
				return false;
			}*/
			var cPhone=$("#clientPhone").val();
			//var isphone=/^\+?\d{3,13}(\-?(\d{6,8}?))?(\-?(\d{4,8}?))*$/; 
			var isphone=/^1[3,5,8]\d{9}$/;
			//var isphone=/^(((13[0-9]{1})|(15[0-9]{1}))+\d{8})$/;
			/*if (cPhone.length!=11 || !isphone.test(cPhone)){
				//$.scojs_message("客户手机格式不正确", $.scojs_message.TYPE_ERROR);
				alert("客户手机格式不正确");
				return false;
			}*/
			
		 	if($("#clientName").val().length==0 ){
				//$.scojs_message("请先在地图上指定 定位代驾地点", $.scojs_message.TYPE_ERROR);
				alert("客户姓名不能为空");
				return false;
			}		

		 	if($("#startpoint").val().length==0 ){
				//$.scojs_message("请先在地图上指定 定位代驾地点", $.scojs_message.TYPE_ERROR);
				alert("出发地不能为空");
				issubmit=false;
				return false;
			}			
			
			/*if($("#serverDate").val().length==0 || $("#serverTime").val().length==0){
				alert("服务时间不能为空");
				issubmit=false;
				return false;
			}*/
			if($("#driverNum").val().length==0){
				//$.scojs_message("人数不能为空", $.scojs_message.TYPE_ERROR);
				alert("人数不能为空");
				issubmit=false;
				return false;
			}
			return true;
	}
	 
	 function pointChange(){
		 var address=$('#point').val();
		 $('#startpoint').val(address);
	 }
</script>
  </div>
  </div>
</td>

<td width="1%" valign="top">
</td>
<td width="39%" valign="top">

	<form id="form1" class="form-horizontal " onsubmit="return formCheck();" action="/order/save3"  method="post" >
	
	<table width="100%" border="1" cellpadding="1" cellspacing="0"   style="border: 1px solid blue; ">
  <tr height="40">
    <td colspan="6" align="center" bgcolor="#e6e6e6">添加新订单
    		<input type="hidden" id="startpoint_longitude" name="order.startpoint_longitude" value="">
    		<input type="hidden" id="startpoint_latitude" name="order.startpoint_latitude" value="">
    		<input type="hidden" id="endpoint_longitude" name="order.endpoint_longitude" value="">
    		<input type="hidden" id="endpoint_latitude" name="order.endpoint_latitude" value="">
    		<input type="hidden" id="newOrderId" name="orderId" value=""/>
    		<input type="hidden" id="order_id" name="order_id" value=""/>
    </td>
  </tr>
  <tr height="40">
    <td  align="left" valign="middle" bgcolor="#E6E6E6"><em>&nbsp;&nbsp;</em>订单类型</td>
    <td colspan="5" >
    	<select name="orderCategoryType" id="orderCategoryType" class="form-control" onchange="orderCategoryTypeChange(this)">
    		<#list session.orderTypeMapList as orderType>
    			<option value="${orderType.value}" <#if orderCategoryType == orderType.value >selected="selected"</#if>>${orderType.name}</option>
    		</#list>
    	</select>
    </td>
  </tr>
  <!--<tr height="40">
    <td  align="left" valign="middle" bgcolor="#E6E6E6"><em>&nbsp;&nbsp;</em>算费规则</td>
    <td colspan="5" >
    	<select name="order.price_rule_id" id="order.price_rule_id" class="form-control">
    		<#list ruleList as rule>
    			<option value="${rule.id}" <#if rule.is_default == 1 >selected="selected"</#if>>${rule.name}</option>
    		</#list>
    	</select>
    </td>
  </tr-->
  <tr height="40">
    <td width="17%" align="left"  valign="middle" bgcolor="#E6E6E6"><em>&nbsp;&nbsp;</em>客户手机</td>
    <td colspan="5">
         <#if telCallNumb ??>
				&nbsp;<input  id="clientPhone" name="clientPhone"  value="${telCallNumb}" type="text" required="" style="height:32px" line-height:32px; size="30" onchange="checkMobile(this.value);">
				<script> checkMobile("${telCallNumb}");</script>
		<#else>
				&nbsp;<input id="clientPhone" name="clientPhone"  value="" type="text" required="" style="height:32px; line-height:32px" size="30" onchange="checkMobile(this.value);">
		</#if>
        <input class="form-control" id="memberID" name="memberID"  value="0" type="hidden" >
        <span class="label label-info" style="padding-left:0px;margin-top:6px;font-size:14px;" id="membertype"></span>
    </td>

  </tr>
  <tr height="40">
    <td  align="left" valign="middle" bgcolor="#E6E6E6"><em>&nbsp;&nbsp;</em>客户姓名</td>
    <td colspan="5" >
    	&nbsp;<input id="clientName" name="clientName" type="text" value="" style="height:32px; line-height:32px">
    <span class="label label-warning" style="padding-left:0px;margin-top:6px;font-size:14px;" id="clientVirtual">0元</span>
    </td>

  </tr>
  <tr height="40">
    <td  colspan="6" align="right" id="todayordernums_div" style="display: none;">
    
    <em>&nbsp;&nbsp;</em>总下单量
    			<label >
				                    <p class="form-control-static" id="allcount" width="100px">
				                    <#if member ??>
				                    <a target='_blank' href='/order/memberOrder/${member.id}'></a>
						            <#else>
						            &nbsp;
						            </#if>
						            
						            </p>
			</label>
	<em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</em>取消
			                    <label>
						            	<p class="form-control-static" id="cancalcount" width="100px"></p>
						            </label>	
	<em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</em>本月单量
	    	<label>
				<p class="form-control-static" id="monthcount" width="100px">&nbsp;</p>
		</label><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</em>
				
    </td>
    <tr>
    	<td>
    	常用地址选择:
    	</td>
    	<td colspan="5">
    		<select onchange="pointChange()" id="point" style="width:400px;">
    			<option value="" selected></option>
    			<#list points as point>
    				<option value="${point.address!""}" >${point.address!""}</option>
    			</#list>
    		</select>
    	</td>
    </tr>
    
  <tr height="40">
    <td align="left" valign="middle" bgcolor="#E6E6E6"><em>&nbsp;&nbsp;</em>出发地</td>
    <td colspan="3">
	    <em>&nbsp;</em>
	    <input placeholder="附近的小区/街道/建筑物/商圈"  id="startpoint" name="order.startpoint" type="text" value="${startpoint!""}" required="" 
	    	   style="height:32px; line-height:32px" onpropertychange="search()" oninput="search()" >
	    <div style="display:none" id="bmapcontainer"></div>
	</td>
	<td colspan="2">
        <span class="input-group-btn">
                <button class="btn btn-default" type="button" id="btn-position" onclick="search()">定位</button>
        </span>
        <span class="input-group-btn">
                <button class="btn btn-default" type="button" id="btn-position" onclick="markBegin()">地图上选择定位点</button>
        </span>
    </td>
  </tr>
  
  <tr height="40" id="hiddOrder">
    <td align="left" valign="middle" bgcolor="#E6E6E6"><em>&nbsp;&nbsp;</em>目的地</td>
    <td colspan="3">
    	<em>&nbsp;</em>
    	<input placeholder="附近的小区/街道/建筑物/商圈"  id="endpoint" name="endpoint" type="text" value="" 
    		   style="height:32px; line-height:32px" onpropertychange="searchEnd()" oninput="searchEnd()">
	</td>
	<td colspan="2">
        <span class="input-group-btn">
            <button class="btn btn-default" type="button" id="btn-position" onclick="searchEnd()">定位</button>
        </span>
        <span class="input-group-btn">
            <button class="btn btn-default" type="button" id="btn-position" onclick="markEnd()">地图上选择定位点</button>
        </span>
    </td>
  </tr>
  
  <tr height="40"  id="hiddOrder1">
	  <td bgcolor="#E6E6E6"><em>&nbsp;&nbsp;</em>希望出发时间</td>
	  <td colspan="2" align="left" valign="middle" >
		<em>&nbsp;</em><input  id="pointTime" name="pointTime" type="text" value="${pointTime!""}" required="" size="20" style="width:160px;height:32px;line-height:32px" 
	    						onfocus="WdatePicker({dateFmt:'yyyy-MM-dd mm:ss',readOnly:true})">
	  </td>
	 <td bgcolor="#E6E6E6"><em>&nbsp;</em><font color="red" size="5">人数</font></td>
	 <td colspan="4" align="left" valign="middle" >
		<div>
		    <input class="spinner" id="driverNum" name="driverNum" type="number" value="1" style="width:32px;height:32px;line-height:32px"/>
		</div>	
	 </td>
  </tr>
  <tr height="40" id="hiddOrder2">
    <td align="left" valign="middle" bgcolor="#E6E6E6"><em>&nbsp;&nbsp;</em>公里数</td>
    <td colspan="2">
       <div style="float:left">
	    	<input class="spinner" id="driverKm" name="driverKm" value="0" style="width:32px;height:32px;line-height:32px"/>
       </div>
    </td>

    <td bgcolor="#E6E6E6"><em>&nbsp;</em>公司定价</td>
    <td colspan="2">
		<input class="spinner" id="driverMoney" name="driverMoney" value="0" style="width:32px;height:32px;line-height:32px"/>
	</td>

  </tr>
  <tr height="40" id="hiddOrder3">
    <td align="left" valign="middle" bgcolor="#E6E6E6"><em>&nbsp;&nbsp;</em>订单来源</td>
    <td colspan="2">
		<#if session.myCompanyName ??>
		     <em>&nbsp;</em><input  id="fromSource" name="fromSource" type="text" value="<#if orderCompanyName?exists>${orderCompanyName}<#else>${session.myCompanyName}</#if>" readonly="true" style="width:200px;height:32px;line-height:32px">
		     <input  id="fromSourceValue" name="fromSourceValue"  value="<#if orderCompany?exists>${orderCompany}<#else>${session.company}</#if>" type="hidden" >
		<#else>
			 <em>&nbsp;</em><input  id="fromSource" name="fromSource" type="text" value="大拇指" readonly="true" style="width:200px;height:32px;line-height:32px">
					 <input  id="fromSourceValue" name="fromSourceValue"  value="10" type="hidden" >
		</#if>

    </td>

    <td bgcolor="#E6E6E6"><em>&nbsp;</em>派单范围</td>
    <td colspan="2">
		<input class="spinner" id="driverRateKm" name="driverRateKm" value="2" style="width:32px;height:32px;line-height:32px"/>
	</td>

  </tr>
  <tr height="40" id="hiddOrder4">
    <td align="left" valign="middle" bgcolor="#E6E6E6"><em>&nbsp;</em>选择优惠券</td>
    <td colspan="2">				            		
    	<em>&nbsp;</em>
    	<select name="coupon" id="coupon" style="height:36px">
		    <option value="">
		                   请选择优惠券
		    </option>
		</select>
	</td>

    <td bgcolor="#E6E6E6"><em>&nbsp;</em>券密码</td>
    <td colspan="2">
    <em>&nbsp;</em><input id="couponPass" name="couponPass" type="text" value=""  style="height:32px;line-height:32px" >
    </td>

  </tr>
  <tr height="120" id="hiddOrder5">
    <td align="left" valign="middle" bgcolor="#E6E6E6"><em>&nbsp;&nbsp;</em>订单备注</td>
    <td colspan="5">
<em>&nbsp;</em><textarea  cols="20" id="memo" name="memo" rows="2" style="width:400px;height:80px;line-height:32px"></textarea>
    </td>

  </tr>
  <tr height="40" >
    <td colspan="6" bgcolor="#E6E6E6" align="center" valign="middle"><br>
     	<button type="button" style="background-color: red;" id="toggleBnt" name="toggleBnt" class="btn btn-primary" onclick="toggle()">收缩项目</button>
         <button type="button" id="submitBnt" name="submitBnt" class="btn btn-primary" onclick="createOrder()">保存订单</button>
         <button type="button" id="submitBnt" name="submitBnt" class="btn btn-primary" onclick="createOrder3()">员工抢单</button>
         <!-- <button type="button" id="submitBnt" name="submitBnt" class="btn btn-primary" onclick="createOrderSelf()">强制派单</button>-->
         <!-- <br><br>
         <button type="button" class="btn btn-info" onclick="javascript:history.back();">返回</button> -->
    </td>
  </tr>
  <tr>
	<td colspan="6">
		<table id="driverTable" width="100%" border="1" cellpadding="1" cellspacing="0"   style="border: 1px solid blue;display:none ">
		<tr>
		  	<td colspan="6" align="center" valign="middle">
			  	<p style="text-align: center;margin-left: 50px; margin-top:5px;">代驾员工号：<input type="text" id="jobNumber" style="height:30px;" onkeypress="if(event.keyCode==13) {selectByJobNumber();return false;}"/>
					<input type="button" class="btn btn-primary" onclick="selectByJobNumber()" value="选择"/>
					<input type="button" class="btn btn-primary" onclick="assigment()" value="派 单"/>
				</p>
			</td>
		</tr>
	</table>
	</form>
	</td>
</tr>
<tr >
	<td colspan="6" style="text-align:center;display:none;" id="selectTd">
		<div>
		<a class="btn btn-primary" onclick="selectAll();"><i class="icon-trash icon-white"></i> 全 选</a> &nbsp;&nbsp;
		<button type="button" class="btn btn-primary" onclick="javascript:history.back();">返回</button>
		<button type="button" class="btn btn-primary" onclick="javascript:assigment2();">选择派单</button>
		</div>
	</td>
</tr>
<tr>
<table class="table table-bordered table-striped" id="showTable" style="display:none;">
	<tr>
		<td style="width:10%;">选择</td>
		<td style="width:5%;">工号</td>
		<td style="width:15%;">姓名</td>
		<td style="width:15%;">距离(公里)</td>
		<td style="width:10%;">积分</td>
		<td style="width:10%;">军衔</td>
		<td style="width:10%;">已完成</td>
		<td style="width:10%;">已取消</td>
		<td style="width:12%;">已接订单数</td>
		<td style="width:10%;">派单</td>
	</tr>
</table>
</tr>

</table>
</form>
 
</td>

</tr>

</table>

<style>
	.tangram-suggestion{border:1px #f5f5f5 solid;background:#fff;line-height:24px;text-indent:12px;padding:0 10px;z-index:1000;}
	.tangram-suggestion-current{background:#3acf87;color:#fff;}
</style>
 <script>
 	var drivers = [];
 	var dirverList;
	var order;
	var driverShow;
   $('.spinner').spinner();
   $("#driverRateKm").val(2);
   $("#driverKm").val(0);
   $("#driverMoney").val(0);
   
   
   function createOrder3(){
 	  $('#form1').attr("action", "/order/save3").submit();
   }
   
   function createOrderSelf(){
 	  //$('#form1').attr("action", "/order/save4").submit();
 	 if(!formCheck()){
 	 	 return;
 	 }
 	 var id=0;
 	 if($('#newOrderId').val().length!=0 ){
 	 	 if(driverr.lenght==0){
 	 		id=$('#newOrderId').val();
 	 		$.ajax({
 				url:'/order/assignment/'+id,
 				data:{'ajax':'1'},
 				success:function(data){
 					dirverList=data.driverList;
 					order=data.order;
 					driverShow=data.driverShowList;
 					initAllMarker(dirverList);
 					markerUser(order);
 					addDriver(driverShow);
 					$("#driverTable").css('display','');
					$("#showTable").css('display','');
					$('#selectTd').css('display','');
 				}
 			});
 	 	 }
 	 	// id=$('#newOrderId').val();
 	 	 //return false;
 		/*$.ajax({
			url:'/order/assignment/'+id,
			data:{'ajax':'1'},
			success:function(data){
				var dirverList=data.driverList;
				var order=data.order;
				var driverShow=data.driverShowList;
				initAllMarker(dirverList);
				markerUser(order);
				addDriver(driverShow);
			}
		});*/
		return false;
 	 }
 	//1.先保存订单数据
		 $('#form1').ajaxSubmit({
			type:'post',
			url:'/order/save4',
			success:function(data){
				debugger;
				var id=data.id;
				$('#newOrderId').val(id);
				$('#order_id').val(id);
				//2.获取司机
				if(id==0){
					return false;
				}
				$.ajax({
					url:'/order/assignment/'+id,
					data:{'ajax':'1'},
					success:function(data){
						dirverList=data.driverList;
						order=data.order;
						driverShow=data.driverShowList;
						initAllMarker(dirverList);
						markerUser(order);
						addDriver(driverShow);
						$("#driverTable").css('display','block');
						$("#showTable").css('display','');
						$('#selectTd').css('display','');
					}
				});
			}
		 });
	
   }
   function createOrder(){
 	  $('#form1').attr("action", "/order/save5").submit();
   }
   	function toggle(){
		$('#hiddOrder').toggle();
		$('#hiddOrder1').toggle();
		$('#hiddOrder2').toggle();
		$('#hiddOrder3').toggle();
		$('#hiddOrder4').toggle();
		$('#hiddOrder5').toggle();
   	}

  //初始化数据库中已有的标点
     function initAllMarker(driverList){
	  debugger;
	  driverr=[];
	  var contents={};
   		for(var i=0;i<driverList.length;i++){
   	   		var driver=driverList[i];
   	   		var point = new BMap.Point(driver.longitude,driver.latitude);
	    	//var point = new BMap.Point(driver.longitude?string(",##0.000000"),driver.latitude?string(",##0.000000"));
			//创建一个标点
			var marker = new BMap.Marker(point);
			//标点右下角显示的LABEL
			var dataLabel = new BMap.Label(driver.name, {offset: new BMap.Size(30, 5)});
			//var dataLabel = new BMap.Label('', {offset: new BMap.Size(13, 23)});
		   	dataLabel.setStyle({border: "0px",backgroundColor:""});
			var img="";
			if(driver.status == 0){
				img='/img/marker/marker_greennew.png';
			}
			else if(driver.status == 1){
				img='/img/marker/marker_bluenew.png';
			}
			else if( driver.status == 2){
				img='/img/marker/marker_rednew.png';
			}
			else if(driver.status == 3){
				img="/img/marker/marker_purplenew.png";
			}
			else if(driver.status == 4){
				img= '/img/marker/marker_purplenew.png';
			}
			else{
				img="/img/marker/marker_yellowback.png";
			}
			var dataIcon= new BMap.Icon(img,
			new BMap.Size(80, 35), {
    			imageOffset: new BMap.Size(0, 0)    //图片的偏移量。为了是图片底部中心对准坐标点。
	  			}
			);
		    //设置标点图标
			marker.setIcon(dataIcon);			    
			//设置标点LABEL
			marker.setLabel(dataLabel);
			//设置ID
			marker.id = driver.id;
			drivers.push({id:driver.id, name:driver.name});
			content = "<table><tr><td width='45%'>";
			content += "<img width='70' src='/upload/default_avatar.gif'>";
		    content += "</td>";
			content += "<td>工号："+driver.job_number+"<br>";
			content += "姓名："+driver.name+"<br>";
			content += "公司："+driver.companyname+"<br>";
			content += "电话："+driver.phone+"<br>";
			content += "已接订单数："+driver.acceptNum+"<br>";
		    /*content += "姓名："+driver.name+"<br>";
	    	content += "电话："+driver.phone+"<br>";
	    	content += "驾照："+driver.driver_license+"<br>";
	    	var sex =driver.sex;
	    	if(sex == 0 ){
		    	content += "性别：男<br>";
	    	}
	    	else if(sex == 1){
	    		content += "性别：女<br>";
	    	}
	    	else{
	    		content += "性别：未知<br>";
	    	}*/
	    	content += "</td></tr>";
	    	content += "<tr><td colspan=2><input type='button' value='选择' onclick='chooseDriver(\""+driver.id+"\",\""+driver.name+"\",\""+driver.acceptNum+"\")'></td></tr>";
	    	content += "</table>";
	    	contents[driver.id]=content;
			marker.addEventListener("mouseover", function(){				
				var infoWindow = new BMap.InfoWindow(contents[this.id]);
				this.openInfoWindow(infoWindow);
			});
			
			
			
			//在地图上打点
			map.addOverlay(marker);
		//	marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
   		}
    }

     function markerUser(x,y){
     	var icon_path = '/img/marker/core_user.png';
     	var point = new BMap.Point(x,y);
 		//创建一个标点
 		var marker = new BMap.Marker(point);
 		//标点右下角显示的LABEL
 		var dataLabel = new BMap.Label("下单用户", {offset: new BMap.Size(13, 23)});
 	    dataLabel.setStyle({border: "solid 1px green",backgroundColor:"white"});
 		var dataIcon= new BMap.Icon(
 			icon_path, 
 			new BMap.Size(45, 45), {
 				imageOffset: new BMap.Size(0, 0)
   			}
 		);
 	    //设置标点图标
 		marker.setIcon(dataIcon);			    
 		//设置标点LABEL
 		marker.setLabel(dataLabel);
 		//在地图上打点
 		map.addOverlay(marker);
     }

     //选择代驾员
     function chooseDriver(id ,name, acceptNum){
         debugger;
        var trId = "driver_" + id ;
         if(document.getElementById(trId)){
              alert('"' + name + '"已选择');
              return;
         }
     	var html = '<tr id="' +trId + '" style="text-align: center;"><td>' + name + '<font color="red">(已接单数：'+acceptNum+')</font><input id="driver_id" name="driver_id" type="hidden" value="' + id + '"></td><td><a class="btn btn-success" href="#" onclick="remove(\'' + id + '\')"><i class="icon-trash icon-white"></i> 取 消</a></td></tr>';
     	$("#driverTable").append(html);
     }

     function addDriver(driverShowList){
		debugger;
		for(var i=0;i<driverShowList.length;i++){
			var driver=driverShowList[i];
			var html='<tr><td style="vertical-align: middle;text-align:center;height:35px;"><input type="checkbox" name="assigmentbox" value="'+driver.id+'" /></td>'+
						 '<td style="vertical-align: middle;text-align:center;height:35px;">'+driver.job_number+'</td>'
						 +'<td style="vertical-align: middle;text-align:center;height:35px;">'+driver.name+'</td>'
						+'<td style="vertical-align: middle;text-align:center;height:35px;">'+driver.distance+'</td>'
						+'<td style="vertical-align: middle;text-align:center;height:35px;">'+driver.point+'</td>'
						+'<td style="vertical-align: middle;text-align:center;height:35px;">';
			debugger;
			if(driver.level==null)
				html+=0;
			else
				html+=driver.level;
			html=html+'</td>'
						+'<td style="vertical-align: middle;text-align:center;height:35px;">'+driver.finishNum+'</td>'
						+'<td style="vertical-align: middle;text-align:center;height:35px;">'+driver.cancelNum+'</td>'
						+'<td style="vertical-align: middle;text-align:center;height:35px;">'+driver.acceptNum+'</td>'
						+'<td style="vertical-align: middle;text-align:center;height:35px;"><button type="button" class="btn btn-primary" onclick="assigment1('+driver.id+')"';
			if(driver.acceptNum>0){
				html=html+'style="background-color:#FF5511;"';
			}
			html=html+'>派单</button></td></tr>';
			$('#showTable').append(html);
		}
		
     }
     
     function remove(id){
     	var trId = "#driver_" + id;
     	$(trId).remove();
     }
     
     function assigment(){
 		if($("#driver_id").val()){
 			var array=$("[name='driver_id']");
 			//1.先保存订单
 			 $('#form1').ajaxSubmit({
				type:'post',
				url:'/order/save4',
				data:{number:array.length},
				success:function(data){
					debugger;
					var id=data.id;
					$('#newOrderId').val(id);
					$('#order_id').val(id);
					//2.保存司机
					var idEach=id.split(";");
					for(var i=0;i<idEach.length;i++){
						//window.location.href="/order/saveJob?driver_id="+driver_ids[i]+"&order_id="+idEach[i];
						 $.ajax({
									url:'/order/saveJob?driver_id='+$(array[i]).val()+'&order_id='+idEach[i],
									type:'post'
								});
					}
					
					//进行跳转
					var orderType=$('#orderCategoryType').val();
					if("UNLOCK"==orderType){
						window.location.href="/categoryorder/unlockList";
					}else if("DELIVERY"==orderType){
						redirect("/categoryorder/deliveryList");
					}else if("PARK"==orderType){
						redirect("/categoryorder/parkList");
					}else{
						window.location.href="/order/acceptList";
					}
				}
		 	});
 		}
 		else{
 			alert("请先选择代驾员");
 		}
 	}
 	function assigment1(driverId){
 		//1.先保存订单
		 $('#form1').ajaxSubmit({
			type:'post',
			url:'/order/save4',
			success:function(data){
				debugger;
				var id=data.id;
				$('#newOrderId').val(id);
				$('#order_id').val(id);
				//2.保存司机
		 		window.location.href="/order/saveJob?driver_id="+driverId+"&order_id="+id+"&driverRateKm="+$('#driverRateKm').val();;
			}
	 	});
 		
 	}
 	
 	function assigment2(){
		var checkObj = $("input[name=assigmentbox]:checked");
		if(checkObj.length<=0){
			Showbo.Msg.alert('请选择需要派送的员工');
		}else{
			var driver_ids = new Array($(checkObj).length);
			for(var i =0;i<$(checkObj).length;i++){
				driver_ids[i]=$($(checkObj)[i]).val();
			}
			//1.先保存订单
			 $('#form1').ajaxSubmit({
				type:'post',
				url:'/order/save4',
				data:{'number':driver_ids.length},//追加司机数量
				success:function(data){
					debugger;
					var id=data.id;
					$('#newOrderId').val(id);
					$('#order_id').val(id);
					//2.保存司机
					//window.location.href="/order/saveJob?driver_id="+driver_ids+"&order_id="+id;
					var idEach=id.split(";");
					for(var i=0;i<idEach.length;i++){
						//window.location.href="/order/saveJob?driver_id="+driver_ids[i]+"&order_id="+idEach[i];
						 $.ajax({
									url:'/order/saveJob?driver_id='+driver_ids[i]+'&order_id='+idEach[i],
									type:'post'
								});
					}
					
					//进行跳转
					var orderType=$('#orderCategoryType').val();
					if("UNLOCK"==orderType){
						window.location.href="/categoryorder/unlockList";
					}else if("DELIVERY"==orderType){
						redirect("/categoryorder/deliveryList");
					}else if("PARK"==orderType){
						redirect("/categoryorder/parkList");
					}else{
						window.location.href="/order/acceptList";
					}
				}
		 	});
			
		}
	}

 	function selectByJobNumber() {
	 	var jobNumber = document.getElementById("jobNumber").value;
	 	if(!jobNumber) {
	 		alert("请输入代驾员工号!");
	 		return false;
	 	}
	 	var driverMap = [];
	 	for(var i=0;i<dirverList.length;i++){
		 	var driver=dirverList[i];
	 		driverMap.push({jobNumber:driver.job_number, id:driver.id, name:driver.name, acceptNum:driver.acceptNum});
	 	}
	 		
	 	var i = 0
	 	for(; i < driverMap.length; i++) {
	 		if(driverMap[i].jobNumber.toLowerCase() == jobNumber.toLowerCase()) {
	 			chooseDriver(driverMap[i].id, driverMap[i].name, driverMap[i].acceptNum);
	 			break;
	 		}
	 	}
	 	if(i >= driverMap.length) alert("当前页面地图上无此代驾驶员！");
	 }

 	function selectAll() {
	 	var bounds = map.getBounds();
	 	var os = map.getOverlays();
	 	if(os && os.length > 0) {
	 		for(var i = 0; i < os.length; i++) {
		 		try{
		 			if(bounds.containsPoint(os[i].getPosition())) {
			 			if(os[i].hasOwnProperty("id")){
			 				var id = os[i].id;
			 				for(var k = 0; k < drivers.length; k++) {
			 					if(drivers[k].id == id) {
			 						chooseDriver(id, drivers[k].name, drivers[k].acceptNum);
			 						break;
			 					}
			 				} 
			 			}
		 				
		 			}
		 		}
	 			catch(e){}
	 		}
	 	}
	 }
$(document).ready(function(){ 
	toggle();
});
   
</script>
<script type="text/javascript" src="/js/map-adress.js"></script>
<script type="text/javascript" src="/js/wdatePicker/WdatePicker.js"></script>
</@layoutWithOutDocType>